<?php
namespace app\service;

use think\facade\Db;

class ArticlecategoryService
{
    public static function getTreeList($param=null)
    {
        $data = Db::name($param['table'])->where(['parent_id'=>0])->order('sort asc')->select()->toArray();
        $list=array();
        $spl='　├　';
        if(!empty($param['spl'])){
            $spl = $param['spl'];
        }
        foreach($data as &$v)
        {
            $v['spl']='';
            array_push($list,$v);
            $menu=Db::name($param['table'])->where(['parent_id'=>$v['id']])->where($param['where'])->order('sort asc')->select()->toArray();
            foreach($menu as &$vv)
            {
                $vv['spl']=$spl;
                array_push($list,$vv);
                $menu2=Db::name($param['table'])->where(['parent_id'=>$vv['id']])->order('sort asc')->select()->toArray();      
                foreach($menu2 as &$vvv)
                {
                    $vvv['spl']=$spl.$spl;
                    array_push($list,$vvv);
                }
            }
        }
        return $list;
    }
    public static function datalist($param=null)
    {
        $where=array();
        if(!empty($param['where']))
        {
            $where=$param['where'];
        }
        $datalist = Db::name($param['table'])->where($where)->order('sort asc')->select()->toArray();
        return $datalist;
    }
    public static function all($param=null)
    {
        $where=array();
        if(!empty($param['where']))
        {
            $where=$param['where'];
        }
        $datalist = Db::name('ArticleCategory')->where($where)->order('sort asc,id desc')->select()->toArray();
        return $datalist;
    }
    public static function payment($param)
    {
        return Db::name('payment')->where(['danwei_id'=>$param['danwei_id']])->order('sort asc')->select()->toArray();
    }
}